const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const path = require('path')
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')

module.exports = {
    mode: 'development',

    entry: './src/index.js',

    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'app.bundle.js'
    },

    optimization: {
        minimize: true,
        minimizer: [
            // 表示保留当前已有的压缩器
            `...`,
            // 添加 CSS 压缩器
            new CssMinimizerPlugin()
        ]
    },

    module: {
        rules: [
            {
                test: /\.css$/i,
                use: [
                    MiniCssExtractPlugin.loader,
                    'css-loader',
                    // 用 PostCSS 处理样式文件
                    {
                        loader: 'postcss-loader',
                        options: {
                            postcssOptions: {
                                plugins: [
                                    ["postcss-preset-env", {
                                        browsers: ['last 2 versions']
                                    }]
                                ],
                            },
                        }
                    }
                ]
            }
        ]
    },

    plugins: [
        new MiniCssExtractPlugin()
    ]
}